package com.waiterxiaoyy.backandroiddesign.Service.impl;


import com.waiterxiaoyy.backandroiddesign.Service.DakaService;
import com.waiterxiaoyy.backandroiddesign.entity.DaKa;
import com.waiterxiaoyy.backandroiddesign.entity.ThisTime;
import com.waiterxiaoyy.backandroiddesign.mapper.MemberMapper;
import com.waiterxiaoyy.backandroiddesign.utils.poi.DakaPoi;
import com.waiterxiaoyy.backandroiddesign.utils.vo.DataVo;
import net.bytebuddy.asm.Advice;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * @author :WaiterXiaoYY
 * @description: TODO
 * @data :2021/1/14 22:39
 */
@Service
public class DakaServiceImpl implements DakaService {
    @Autowired
    private MemberMapper memberMapper;
    @Override
    public DataVo addKa(String fileName) {
        DataVo dataVo = new DataVo();
        dataVo.setCode(202);
        dataVo.setMsg("出错");
        ThisTime thisTime = new ThisTime();
        thisTime.setThistime(Long.parseLong(fileName));
        try {
            if(memberMapper.exisTime(thisTime) == 1) {
                dataVo.setCode(203);
                dataVo.setMsg("日期数据已存在");
                throw new Exception();
            }
            List<DaKa> daKaList = DakaPoi.getDaka(fileName);
            if(daKaList.size() > 0) {
                for(DaKa daKa : daKaList) {
                    memberMapper.addKa(daKa);
                }
            }
            memberMapper.addTime(thisTime);
            dataVo.setCode(200);
            dataVo.setMsg("成功");
            dataVo.setData(daKaList);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return dataVo;
        }

    }

    @Override
    public List<DaKa> export() {
        return memberMapper.export();
    }
}
